package com.cheng.example.atguigu.view2.client20;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;


/**
 * 多个线程都往容器添加不会有任何问题
 */
public class ContainerNotSafeDemo2 {
    public static void main(String[] args) throws InterruptedException {

        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(0, 8));
//                System.out.println(list.toString());
            }, String.valueOf(i)).start();
        }


        while (Thread.activeCount() > 2) {
            Thread.yield();
        }
        System.out.println(Thread.activeCount());

        System.out.println(list.size());

    }
}
